const app = getApp();
Component({
  data: {
    TabCur: 0,
    scrollLeft:0,
    list: []
  },
  attached(){
    this.isLogin();
  },
  methods: {
    isLogin() {
      let _isLogin = wx.getStorageSync('isWxLogin');
      if(!_isLogin){//TOOD 提示用户登录
        wx.redirectTo({
          url: '/pages/index/index?tab=my'
        });
      }else{
        let _loginU = wx.getStorageSync('loginUserInfo');
        this.setData({
          userInfo: _loginU,
          isWxLogin: true
        });
        if(wx.getStorageSync('tabSelectIndex')){
          this.gotoTab(wx.getStorageSync('tabSelectIndex'));
        }else{
          this.getActivitys('/join/list');
        }
      }
    },

    gotoTab (_sIndex) {
      this.setData({
        TabCur: _sIndex,
        scrollLeft: (_sIndex-1)*60
      });
      let _u = '/join/list';
      if(_sIndex == 1){
        _u = '/fav/list';
      }else if(_sIndex == 2) {
        _u = '/care/list';
      }
      this.getActivitys(_u);
    },

    tabSelect(e) {
      let _sIndex = e.currentTarget.dataset.id;
      this.gotoTab(_sIndex);
    },

    getActivitys(t) {
      let _that = this;
      var _url = app.globalData.apiServerUrl + t;
      wx.request({
        url: _url,
        method: 'POST',
        data: {
          userId: _that.data.userInfo.userId
        },
        header: {
          'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
        },
        success(res) {
          let _d = res.data;
          _that.setData({
            list: _d.records
          });
        }
      })
    },



  }
})
